package tmproject.hlhj.fhp.cartrans.http

import android.content.Context
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableBody
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.Observable
import io.reactivex.Scheduler
import io.reactivex.schedulers.Schedulers
import rx.android.schedulers.AndroidSchedulers
import tmproject.hlhj.fhp.cartrans.convert.JsonConvert
import tmproject.hlhj.fhp.cartrans.javaBean.*
import java.io.File

/**
 * Created by Administrator on 2018/8/23/023.
 */
object Apis {

    /**
     * 短信
     */
    fun sendSms(phone:String): Observable<Response<BaseBean>>? {
        return OkGo.post<BaseBean>(Urls.BaseUrl+Urls.GetSms)
                .params("mobile",phone)
                .converter(object : JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(io.reactivex.schedulers.Schedulers.io())
    }

    /**
     * 注册
     */

    fun regis(name:String,mobile:String,sex:String,age:Int,id_no:String
    ,jsz_expire_date:String,zgz_expire_date:String,tractor_id:String,id_pic:File,id_pic_back:File
    ,jsz_pic:File,zgz_pic:File): Observable<Response<RegisBean>>? {

       return OkGo.post<RegisBean>(Urls.BaseUrl+Urls.Regis)
                .params("name",name)
                .params("mobile",mobile)
                .params("sex",sex)
                .params("age",age)
                .params("id_no",id_no)
                .params("jsz_expire_date",jsz_expire_date)
                .params("zgz_expire_date",zgz_expire_date)
                .params("vehicle_id",tractor_id)
                .params("id_pic",id_pic)
                .params("id_pic_back",id_pic_back)
                .params("jsz_pic",jsz_pic)
                .params("zgz_pic",zgz_pic)

                .converter(object : JsonConvert<RegisBean>(){})
                .adapt(ObservableResponse<RegisBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 登录
     */
    fun login(mobile:String,sms_code:String): Observable<Response<LoginBean>>? {
       return OkGo.post<LoginBean>(Urls.BaseUrl+Urls.Login)
                .params("mobile",mobile)
                .params("sms_code",sms_code)
                .converter(object : JsonConvert<LoginBean>(){})
                .adapt(ObservableResponse<LoginBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 获取车牌号
     */

    fun getCarNum(): Observable<Response<CarNumBean>>? {
        return OkGo.get<CarNumBean>(Urls.BaseUrl+Urls.getCarNum)
                .converter(object : JsonConvert<CarNumBean>(){})
                .adapt(ObservableResponse<CarNumBean>())
                .subscribeOn(Schedulers.io())

    }
    /**
     *获取司机信息
     */
    fun getDriverInfo(token:String?): Observable<Response<DriverInfoBean>>? {
        return OkGo.get<DriverInfoBean>(Urls.BaseUrl+Urls.getDriverInfo)
                .params("token",token)
                .converter(object : JsonConvert<DriverInfoBean>(){})
                .adapt(ObservableResponse<DriverInfoBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 更新信息
     */
    fun changeInfo(params: HttpParams): Observable<Response<BaseBean>>? {
       return OkGo.post<BaseBean>(Urls.BaseUrl+Urls.changeInfo)
                .params(params)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }
    fun getA(context: Context){
        OkGo.get<String>("0")
                .converter(object : JsonConvert<String>(){})
                .adapt(ObservableResponse<String>())
    }

    fun getClassList(context: Context,token:String?,page:Int,pageSize:Int): Observable<Response<ClassListBean>> {
       return OkGo.get<ClassListBean>(Urls.BaseUrl+Urls.getClassList)
               .params("token",token)
               .params("page",page)
               .params("pageSize",pageSize)
                .converter(object : JsonConvert<ClassListBean>(){})
                .adapt(ObservableResponse<ClassListBean>())
                .subscribeOn(Schedulers.io())
    }
    /*消息列表*/
    fun getNotices(): Observable<Response<NoticeListBean>>? {
        return OkGo.get<NoticeListBean>("http://tm.trf9.cn/hlhj_goddess_vote/api/get_style")
                .converter(object : JsonConvert<NoticeListBean>(){})
                .adapt(ObservableResponse<NoticeListBean>())
                .subscribeOn(Schedulers.io())
    }
    /*消息详情*/
    fun getNoticeDetail(token: String?,id:Int): Observable<Response<NoticeDetailBean>>? {
        return OkGo.get<NoticeDetailBean>(Urls.BaseUrl+Urls.noticeDetail)
                .params("token",token)
                .params("id",id)
                .converter(object : JsonConvert<NoticeDetailBean>(){})
                .adapt(ObservableResponse<NoticeDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 课程详情
     */
    fun getClassDetail(id:Int,token: String?): Observable<Response<ClassDetailBean>>? {
       return OkGo.get<ClassDetailBean>(Urls.BaseUrl+Urls.classDetail)
                .params("token",token)
                .params("id",id)
                .converter(object :JsonConvert<ClassDetailBean>(){})
                .adapt(ObservableResponse<ClassDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 学习详情
     */
    fun getLearnInfo(token:String?): Observable<Response<LearInfoBean>>? {
       return OkGo.get<LearInfoBean>(Urls.BaseUrl+Urls.getLearInfo)
                .params("token",token)
                .converter(object :JsonConvert<LearInfoBean>(){})
                .adapt(ObservableResponse<LearInfoBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 保存学习
     */
    fun saveClass(token: String?,id: Int,learned_time:String): Observable<Response<SaveClassBean>>? {
      return  OkGo.get<SaveClassBean>(Urls.BaseUrl+Urls.saveClass)
                .params("token",token)
                .params("id",id)
                .params("learned_time",learned_time)
                .converter(object :JsonConvert<SaveClassBean>(){})
                .adapt(ObservableResponse<SaveClassBean>())
                .subscribeOn(Schedulers.io())
    }
    fun saveClass(token: String?,id: Int,learned_time:String,
                  driver_pic:File,sign_pic:File): Observable<Response<SaveClassBean>>? {
      return  OkGo.post<SaveClassBean>(Urls.BaseUrl+Urls.saveClass+"?token=${token}&id=${id}&learned_time=${learned_time}")
                 .params("driver_pic",driver_pic)
                .params("sign_pic",sign_pic)
                .converter(object :JsonConvert<SaveClassBean>(){})
                .adapt(ObservableResponse<SaveClassBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获取未读消息数量
     */
    fun getUnReadNum(token: String?): Observable<Response<UnReadNumBean>>? {
        return OkGo.get<UnReadNumBean>(Urls.BaseUrl+Urls.getUnReadNum)
                .params("token",token)
                .converter(object :JsonConvert<UnReadNumBean>(){})
                .adapt(ObservableResponse<UnReadNumBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 获取消息列表
     */
    fun getNoticeList(token: String?,page: Int): Observable<Response<NoticeListBean>>? {
        return OkGo.get<NoticeListBean>(Urls.BaseUrl+Urls.getNoticeList)
                .params("token",token)
                .params("page",page)
                .converter(object :JsonConvert<NoticeListBean>(){})
                .adapt(ObservableResponse<NoticeListBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 考试列表
     */

    fun getExamList(token: String?,page: Int,pageSize: Int): Observable<Response<ExamListBean>>? {
        return OkGo.get<ExamListBean>(Urls.BaseUrl+Urls.getExamList)
                .params("token",token)
                .params("page",page)
                .params("page_size",pageSize)
                .converter(object :JsonConvert<ExamListBean>(){})
                .adapt(ObservableResponse<ExamListBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 考试规则
     */
    fun getExamRule(token: String?,id: Int): Observable<Response<ExamRuleBean>>? {
        return OkGo.get<ExamRuleBean>(Urls.BaseUrl+Urls.getExamRule)
                .params("token",token)
                .params("id",id)
                .converter(object :JsonConvert<ExamRuleBean>(){})
                .adapt(ObservableResponse<ExamRuleBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 考试题目详情
     */
    fun getExamDetail(token: String?,id:Int): Observable<Response<ExamDetailBean>>? {
        return OkGo.get<ExamDetailBean>(Urls.BaseUrl+Urls.getExamDetail)
                .params("token",token)
                .params("id",id)
                .converter(object :JsonConvert<ExamDetailBean>(){})
                .adapt(ObservableResponse<ExamDetailBean>())
                .subscribeOn(Schedulers.io())
        }
    /**
     * 提交试卷
     */
    fun commitExam(token: String?,id: Int,correct_num:Int,pic:File,sign_pic:File): Observable<Response<BaseBean>>? {
        return OkGo.post<BaseBean>(Urls.BaseUrl+Urls.commitExam+"?token=${token}&id=${id}&correct_num=${correct_num}")
          /*      .params("token",token)
                .params("id",id)
                .params("correct_num",correct_num)*/
                .params("pic",pic)
                .params("sign_pic",sign_pic)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 回顾列表
     */
    fun getReviewList(token: String?,page:Int): Observable<Response<ReViewListBean>>? {
        return OkGo.get<ReViewListBean>(Urls.BaseUrl+Urls.reView)
                .params("token",token)
                .params("page",page)
                .converter(object :JsonConvert<ReViewListBean>(){})
                .adapt(ObservableResponse<ReViewListBean>())
                .subscribeOn(Schedulers.io())

    }
    /**
     *
     */
    fun getExamTimes(token: String?): Observable<Response<ExamTImesBean>>? {
        return OkGo.get<ExamTImesBean>(Urls.BaseUrl+Urls.examTimes)
                .params("token",token)
                .converter(object :JsonConvert<ExamTImesBean>(){})
                .adapt(ObservableResponse<ExamTImesBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 关于我们
     */
    fun getAboutUs(token: String?): Observable<Response<AboutUsBean>>? {
        return OkGo.get<AboutUsBean>(Urls.BaseUrl+Urls.aboutUs)
                .params("token",token)
                .converter(object :JsonConvert<AboutUsBean>(){})
                .adapt(ObservableResponse<AboutUsBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 修改头像
     */

    fun changeHead(token: String?,head:File): Observable<Response<BaseBean>>? {
       return OkGo.post<BaseBean>(Urls.BaseUrl+Urls.ChangeHead)
                .params("token",token)
                .params("head_pic",head)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获取信息
     */
    fun getCarInfo(token: String,id: Int): Observable<Response<CarInfoBean>>? {
        return  OkGo.get<CarInfoBean>(Urls.BaseUrl+Urls.CarInfo)
                .params("token",token)
                .params("id",id)
                .converter(object :JsonConvert<CarInfoBean>(){})
                .adapt(ObservableResponse<CarInfoBean>())
                .subscribeOn(Schedulers.io())
    }
}
